package com.ddwl.user.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.schema.bo.user.AccountQueryBo;
import com.ddwl.user.dao.model.Account;
import com.ddwl.user.dao.mapper.AccountMapper;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Account)数据处理
 *
 * @author zach
 * @since 2020-07-27 16:29:58
 */
@Repository
public class AccountDao extends TkDao<AccountMapper, Account> {

    @Resource
    private AccountMapper accountMapper;

    public Account queryAccountByUserName(String userName){
        Account account = new Account();
        account.setUsername(userName);
        return selectOne(account);
    }

    public List<Account> queryPage(AccountQueryBo bo){
        Example example = getExample();
        example.and().andLike("username", MySqlUtil.rightLike(bo.getUsername()))
                .andLike("nickname",MySqlUtil.rightLike(bo.getNickname()))
                .andEqualTo("status",bo.getStatus())
                .andGreaterThanOrEqualTo("gmtCreated",bo.getStartTime())
                .andLessThan("gmtCreated",bo.getEndTime());
        return baseMapper.selectByExample(example);

    }

    public List<Account> getAll() {
        Example example = new Example(Account.class);
        return accountMapper.selectByExample(example);
    }

    public void changeId(Map<String, String> map) {
        accountMapper.changeId(map);
    }
}